$(document).ready(function() {
    var timer = setInterval(search,2000);
    // 搜索框自执行
    function search(){
        $.ajax({
            type: 'get',
            url: '/AllShop/',
            dataType : 'json',
            success : function (data){
                console.log(data);
                var sname = data.name;
                $('.sea').prop('placeholder',sname);

                $('.addsea').click(function(){
                    clearInterval(timer);
                    $('.sea').prop('placeholder',' ');
                    $('.sea').val(sname);
                });
            },
            error : function () {
                console.log('AJAX执行失败!')
            }
        });
    }

    $('Attrsea').click(function(){
        clearInterval(timer);
    });
    
    // 表单验证
    $('.sea').focus(function(){
        clearInterval(timer);
    });

    $('.sea').blur(function(){
        var timer = setInterval(search,2000);
    });

    $('.sea').keyup(function(){
        var str = $(this).val();
        var ret = /^[\u4E00-\u9FA5A-Za-z0-9_]+$/;

        if(ret.test(str) == false){
          $(this).val('').prop('placeholder','梅亭');
        }
    });
});